ValueFolderTemp='C:\Users\Remy Neveu\Desktop\Etude IRM\Analyse\cc in2p3\Nature\ResultsJournal\';
ValueFolderTemp2='C:\Users\Remy Neveu\Desktop\Etude IRM\Analyse\cc in2p3\Nature\ResultsEditor\';
load([ValueFolderTemp 'ResultsThirdLevelDistributionOutliers.mat']);
VecDistribution=VecResults;
load('C:\Users\Remy Neveu\Desktop\Etude IRM\Analyse\cc in2p3\Nature\EtudeNature.mat');
VecEditors1Temp(1,:)=[];
VecValueEditor=VecEditors1Temp;
load('C:\Users\Remy Neveu\Desktop\Etude IRM\Analyse\cc in2p3\Nature\DonneesNature.mat');
VecValueJournal=VecJournalTemp;
ValueCutoff=1.25;
VecResultsTemp1=[];
VecResultsTemp2=[];
VecResultsTemp13=[];
VecResultsTemp23=[];
VecResultsTemp11=[];
VecResultsTemp22=[];
VecValueYear=[0 1 2 3 4 5 10];
VecValueMax=[80 8 15 23 30 38 76];
nMonthMax=12;
n1Temp=0;
n1Temp3=0;
VecFigure=[];
VecFigure2=[];
VecValueFigure=[];
VecValueSlope=[1.34 1.98];
VecResultsEditorsJournalBefore=[14 4;43 33;64 12;103 28;132 21;149 28;199 4;282 33;241 2];
for n1=1:323
    ValueTemp=find(VecDistribution(:,1)==n1);
    ValueStartEditor=VecValueEditor{n1,22};
    if size(ValueTemp,1)==1
        if VecDistribution(ValueTemp,2)<=ValueCutoff&&n1~=11
            ValueJournal=VecValueEditor{n1,11};
            ValueTempBefore=find(VecResultsEditorsJournalBefore(:,1)==n1);
            if size(ValueTempBefore,1)==1
                n3=VecResultsEditorsJournalBefore(ValueTempBefore,2);
            else
                n3=1;
                TestTemp=0;
                while n3<=size(VecValueJournal,1)&&TestTemp==0
                    if strcmpi(ValueJournal,VecValueJournal{n3,1})==1
                        TestTemp=1;
                    else
                        n3=n3+1;
                    end
                end
            end
            load([ValueFolderTemp2 'FileAnalysisEditor' num2str(n1) '.mat']);
            load([ValueFolderTemp2 'FileAnalysisCharacteristicsEditor' num2str(n1) '.mat']);
            VecValueTemp2=[];
            VecValueTemp22=[];
            n2Temp=0;
            if n3>=32
                ValueSlope=VecValueSlope(1,1);
            else
                ValueSlope=VecValueSlope(1,2);
            end
            for n2=1:33
                if n2==n3
%                     eval(['VecValueTemp=VecResultsEditorAuthors2FilteredJournal' num2str(n2) ';']);
%                     eval(['VecValueTemp=VecResultsEditorAuthors2Journal' num2str(n2) ';']);
                    eval(['VecValueTemp=VecResultsEditorAffiliation2Journal' num2str(n2) ';']);
                    if sum(VecValueTemp(2,1:24))>0
                        VecValueTemp22=VecValueTemp;
                    else
                        VecValueTemp22=NaN(2,168);
                    end
                else
%                     eval(['VecValueTemp=VecResultsEditorAuthors1FilteredJournal' num2str(n2) ';']);
%                     eval(['VecValueTemp=VecResultsEditorAuthors1Journal' num2str(n2) ';']);
                    eval(['VecValueTemp=VecResultsEditorAffiliation1Journal' num2str(n2) ';']);
                    if sum(VecValueTemp(2,1:24))>0
                        VecValueTemp2=[VecValueTemp2;VecValueTemp];
                        n2Temp=n2Temp+1;
                    end
                end
            end
            VecValueTemp23=1:2:n2Temp*2;
            VecValueTemp23=VecValueTemp23';
            for n4=1:size(VecValueTemp23,1)
                for n5=2:2:size(VecValueTemp2,2)/2
                    if VecValueTemp2(VecValueTemp23(n4,1)+1,(n5-1)*2+1)==0||VecValueTemp2(VecValueTemp23(n4,1)+1,(n5-1)*2+2)==0
                        VecValueTemp2(VecValueTemp23(n4,1),(n5-1)*2+1)=NaN;
                        VecValueTemp2(VecValueTemp23(n4,1)+1,(n5-1)*2+1)=NaN;
                        VecValueTemp2(VecValueTemp23(n4,1),(n5-1)*2+2)=NaN;
                        VecValueTemp2(VecValueTemp23(n4,1)+1,(n5-1)*2+2)=NaN;
                    end
                end
            end
            for n5=2:2:size(VecValueTemp22,2)/2
                if VecValueTemp22(2,(n5-1)*2+1)==0||VecValueTemp22(2,(n5-1)*2+2)==0
                    VecValueTemp22(1,(n5-1)*2+1)=NaN;
                    VecValueTemp22(2,(n5-1)*2+1)=NaN;
                    VecValueTemp22(1,(n5-1)*2+2)=NaN;
                    VecValueTemp22(2,(n5-1)*2+2)=NaN;
                end
            end
            n5=2*nMonthMax+8;
            VecValueTemp24=2:2:n2Temp*2;
            VecValueTemp24=VecValueTemp24';
%             VecValueFigure=[VecValueFigure;(VecValueTemp2(VecValueTemp23,(n5-1)*2+1)-VecValueTemp2(VecValueTemp23,(n5-1)*2+2))*2./(VecValueTemp2(VecValueTemp23,(n5-1)*2+1)+VecValueTemp2(VecValueTemp23,(n5-1)*2+2))*100 VecValueTemp2(VecValueTemp23,(n5-1)*2+1)./VecValueTemp2(VecValueTemp24,(n5-1)*2+1)*100-VecValueTemp2(VecValueTemp23,(n5-1)*2+2)./VecValueTemp2(VecValueTemp24,(n5-1)*2+2)*100 VecResultsEditor(1,3)*ones(size(VecValueTemp23,1),1) VecResultsEditor(1,27)*ones(size(VecValueTemp23,1),1) n1*ones(size(VecValueTemp23,1),1) ones(size(VecValueTemp23,1),1)];
%             VecValueFigure=[VecValueFigure;(VecValueTemp22(1,(n5-1)*2+1)-VecValueTemp22(1,(n5-1)*2+2))*2./(VecValueTemp22(1,(n5-1)*2+1)+VecValueTemp22(1,(n5-1)*2+2))*100 VecValueTemp22(1,(n5-1)*2+1)./VecValueTemp22(2,(n5-1)*2+1)*100-VecValueTemp22(1,(n5-1)*2+2)./VecValueTemp22(2,(n5-1)*2+2)*100 VecResultsEditor(1,3) VecResultsEditor(1,27) n1 2];
            VecValueTemp25=VecValueTemp2(VecValueTemp23,:)./VecValueTemp2(VecValueTemp24,:);
            VecValueTemp25=nanmean(VecValueTemp25,1);
            VecValueTemp26=nanmean(VecValueTemp2(VecValueTemp23,:)-VecValueTemp2(VecValueTemp24,:),1);
            VecValueTemp27=nanmean(VecValueTemp2(VecValueTemp23,:),1);
            if size(VecValueTemp27,2)>0
                if VecResultsEditor(1,16)<=3.61
                    ValueGroupEditor=1;
                else
                    if VecResultsEditor(1,16)>=5.61&&VecResultsEditor(1,16)<=9.24
%                     if VecResultsEditor(1,16)>=5.61
                        ValueGroupEditor=2;
                    else
                        ValueGroupEditor=0;
                    end
                end
                % Case of articles of co authors which are published in all Nature journals except the editor's one
                VecValueTemp3=[];
                for n2=1:size(VecValueYear,2)*nMonthMax
%                     VecValueTemp3=[VecValueTemp3;(VecValueTemp27(1,(n2-1)*2+1)-VecValueTemp27(1,(n2-1)*2+2))*2/(VecValueTemp27(1,(n2-1)*2+1)+VecValueTemp27(1,(n2-1)*2+2))*100 VecValueTemp22(1,(n2-1)*2+1)/VecValueTemp22(2,(n2-1)*2+1)*100-(VecValueTemp22(1,(n2-1)*2+2)/VecValueTemp22(2,(n2-1)*2+2))*100-VecValueTemp25(1,(n2-1)*2+1)*100+VecValueTemp25(1,(n2-1)*2+2)*100];
                    VecValueTemp3=[VecValueTemp3;VecValueTemp27(1,(n2-1)*2+1)-VecValueTemp27(1,(n2-1)*2+2) VecValueTemp22(1,(n2-1)*2+1)-VecValueTemp22(1,(n2-1)*2+2)];
                    VecResultsTemp11=[VecResultsTemp11;VecValueTemp27(1,(n2-1)*2+1) VecValueTemp27(1,(n2-1)*2+2) 1 VecResultsEditor(1,23) VecResultsEditor(1,3) VecResultsEditor(1,16) VecResultsEditor(1,27)];
                end
                VecValueTemp4=[VecResultsEditor(1,27) VecResultsEditor(1,1)+VecResultsEditor(1,2) VecResultsEditor(1,16) VecResultsEditor(1,27)];
                VecValueTemp3=[VecValueTemp3 repmat(VecValueTemp4,size(VecValueTemp3,1),1) n1*ones(size(VecValueTemp3,1),1)];
                if size(ValueStartEditor,2)<3||size(ValueTempBefore,1)==1
                    VecResultsTemp1=[VecResultsTemp1;VecValueTemp3];
                else
                    VecResultsTemp13=[VecResultsTemp13;VecValueTemp3];
                end
                % Case of articles of co authors which are published in the journal of the editor only
                VecValueTemp32=[];
                for n2=1:size(VecValueYear,2)*nMonthMax
%                     VecValueTemp32=[VecValueTemp32;(VecValueTemp22(1,(n2-1)*2+1)-VecValueTemp22(1,(n2-1)*2+2))*2/(VecValueTemp22(1,(n2-1)*2+1)+VecValueTemp22(1,(n2-1)*2+2))*100 VecValueTemp22(1,(n2-1)*2+1)/VecValueTemp22(2,(n2-1)*2+1)*100-(VecValueTemp22(1,(n2-1)*2+2)/VecValueTemp22(2,(n2-1)*2+2))*100];
                    VecValueTemp32=[VecValueTemp32;VecValueTemp22(1,(n2-1)*2+1)-VecValueTemp22(1,(n2-1)*2+2) VecValueTemp22(1,(n2-1)*2+1)./VecValueTemp22(2,(n2-1)*2+1)*100-VecValueTemp22(1,(n2-1)*2+2)./VecValueTemp22(2,(n2-1)*2+2)*100];
                    VecResultsTemp22=[VecResultsTemp22;VecValueTemp22(1,(n2-1)*2+1) VecValueTemp22(1,(n2-1)*2+2) 1 VecResultsEditor(1,23) VecResultsEditor(1,3) VecResultsEditor(1,16) VecResultsEditor(1,27)];
                end
                VecValueTemp32=[VecValueTemp32 repmat(VecValueTemp4,size(VecValueTemp3,1),1) n1*ones(size(VecValueTemp32,1),1)];
                if size(ValueStartEditor,2)<3||size(ValueTempBefore,1)==1
                    VecResultsTemp2=[VecResultsTemp2;VecValueTemp32];
                    n2=2*nMonthMax+8;
                    VecFigure=[VecFigure;VecValueTemp27(1,(n2-1)*2+2) VecValueTemp27(1,(n2-1)*2+1) VecValueTemp22(1,(n2-1)*2+2) VecValueTemp22(1,(n2-1)*2+1) VecResultsEditor(1,3) VecResultsEditor(1,27) n1 1 1 ValueGroupEditor];
                    VecFigure2=[VecFigure2;VecValueTemp22(2,(n2-1)*2+2) VecValueTemp22(2,(n2-1)*2+1) VecValueTemp22(1,(n2-1)*2+2) VecValueTemp22(1,(n2-1)*2+1) VecResultsEditor(1,1) VecResultsEditor(1,16) VecResultsEditor(1,27) ValueSlope n1 n3 1 1 ValueGroupEditor];
                else
                    VecResultsTemp23=[VecResultsTemp23;VecValueTemp32];
                    n2=2*nMonthMax+8;
                    VecFigure=[VecFigure;VecValueTemp27(1,(n2-1)*2+2) VecValueTemp27(1,(n2-1)*2+1) VecValueTemp22(1,(n2-1)*2+2) VecValueTemp22(1,(n2-1)*2+1) VecResultsEditor(1,3) VecResultsEditor(1,27) n1 1 2 ValueGroupEditor];
                    VecFigure2=[VecFigure2;VecValueTemp22(2,(n2-1)*2+2) VecValueTemp22(2,(n2-1)*2+1) VecValueTemp22(1,(n2-1)*2+2) VecValueTemp22(1,(n2-1)*2+1) VecResultsEditor(1,1) VecResultsEditor(1,16) VecResultsEditor(1,27) ValueSlope n1 n3 1 2 ValueGroupEditor];
                end
                VecValueTemp2=[];
                VecValueTemp22=[];
                n2Temp=0;
                for n2=1:33
                    if n2==n3
                        eval(['VecValueTemp=VecResultsEditorAuthors2FilteredJournal' num2str(n2) ';']);
%                         eval(['VecValueTemp=VecResultsEditorAffiliation2Journal' num2str(n2) ';']);
                        VecValueTemp22=VecValueTemp;
                    else
                        eval(['VecValueTemp=VecResultsEditorAuthors1FilteredJournal' num2str(n2) ';']);
%                         eval(['VecValueTemp=VecResultsEditorAffiliation1Journal' num2str(n2) ';']);
                        VecValueTemp2=[VecValueTemp2;VecValueTemp];
                        n2Temp=n2Temp+1;
                    end
                end
                VecValueTemp23=1:2:n2Temp*2;
                VecValueTemp23=VecValueTemp23';
                for n4=1:size(VecValueTemp23,1)
                    for n5=1:size(VecValueTemp2,2)
                        if VecValueTemp2(VecValueTemp23(n4,1)+1,n5)==0
                            VecValueTemp2(VecValueTemp23(n4,1),n5)=NaN;
                            VecValueTemp2(VecValueTemp23(n4,1)+1,n5)=NaN;
                        end
                    end
                end
                for n5=1:size(VecValueTemp22,2)
                    if VecValueTemp22(2,n5)==0
                        VecValueTemp22(1,n5)=NaN;
                        VecValueTemp22(2,n5)=NaN;
                    end
                end
                VecValueTemp24=2:2:n2Temp*2;
                VecValueTemp24=VecValueTemp24';
                VecValueTemp25=nanmean(VecValueTemp25,1);
                VecValueTemp26=nanmean(VecValueTemp2(VecValueTemp23,:)-VecValueTemp2(VecValueTemp24,:),1);
                VecValueTemp27=nanmean(VecValueTemp2(VecValueTemp23,:),1);
                if size(ValueStartEditor,2)<3||size(ValueTempBefore,1)==1
                    n2=2*nMonthMax+8;
                    VecFigure=[VecFigure;VecValueTemp27(1,(n2-1)*2+2) VecValueTemp27(1,(n2-1)*2+1) VecValueTemp22(1,(n2-1)*2+2) VecValueTemp22(1,(n2-1)*2+1) VecResultsEditor(1,3) VecResultsEditor(1,27) n1 2 1 ValueGroupEditor];
                    VecFigure2=[VecFigure2;VecValueTemp22(2,(n2-1)*2+2) VecValueTemp22(2,(n2-1)*2+1) VecValueTemp22(1,(n2-1)*2+2) VecValueTemp22(1,(n2-1)*2+1) VecResultsEditor(1,1) VecResultsEditor(1,16) VecResultsEditor(1,27) ValueSlope n3 n1 2 1 ValueGroupEditor];
                else
                    n2=2*nMonthMax+8;
                    VecFigure=[VecFigure;VecValueTemp27(1,(n2-1)*2+2) VecValueTemp27(1,(n2-1)*2+1) VecValueTemp22(1,(n2-1)*2+2) VecValueTemp22(1,(n2-1)*2+1) VecResultsEditor(1,3) VecResultsEditor(1,27) n1 2 2 ValueGroupEditor];
                    VecFigure2=[VecFigure2;VecValueTemp22(2,(n2-1)*2+2) VecValueTemp22(2,(n2-1)*2+1) VecValueTemp22(1,(n2-1)*2+2) VecValueTemp22(1,(n2-1)*2+1) VecResultsEditor(1,1) VecResultsEditor(1,16) VecResultsEditor(1,27) ValueSlope n3 n1 2 2 ValueGroupEditor];
                end
                if size(ValueStartEditor,2)<3||size(ValueTempBefore,1)==1
                    n1Temp=n1Temp+1;
                else
                    n1Temp3=n1Temp3+1;
                end
            end
        end
    end
end

% save([ValueFolderTemp2 'FichierFigureCoAuthorsAffiliationOtherJournalsNonFilteredEditorialPolicy.mat'],'VecFigure');
% save([ValueFolderTemp2 'FichierFigureCoAuthorsAffiliationOtherJournalsEditorialPolicyFull.mat'],'VecFigure');
save([ValueFolderTemp2 'FichierFigureCoAuthorsAffiliationOtherJournalsEditorialPolicyScience.mat'],'VecFigure');
% save([ValueFolderTemp2 'FichierFigureCoAuthorsAffiliationOtherJournalsEditorialPolicyScienceFull.mat'],'VecFigure');
% save([ValueFolderTemp2 'FichierFigureCoAuthorsAffiliationOtherJournals2EditorialPolicy.mat'],'VecFigure2');
% save([ValueFolderTemp2 'AnalyseMixedModelCoAuthorsNatureNonFilteredEditorialPolicy.mat'],'VecValueFigure');
% save([ValueFolderTemp2 'AnalyseRobustnessCoAuthorsAffiliationNatureNonFilteredEditorialPolicy.mat'],'VecResultsTemp1','VecResultsTemp23','n1Temp3','VecResultsTemp2','VecValueYear','nMonthMax','n1Temp');

